﻿Imports KumaSystem.Activities.FileSystem
Imports NUnit.Framework
Imports Microsoft.Activities.UnitTesting

<TestFixture()>
Public Class TestGetFolderList

    <SetUp()>
    Public Sub Setup()
        If Not IO.Directory.Exists("D:\ActivityTest") Then IO.Directory.CreateDirectory("D:\ActivityTest")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.Directory.Exists("D:\ActivityTest\TestDestination") Then IO.Directory.CreateDirectory("D:\ActivityTest\TestDestination")
        For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination")
            My.Computer.FileSystem.DeleteFile(childFile)
        Next
        If Not IO.File.Exists("D:\ActivityTest\Test1.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\Test1.txt", "This is test strings", False)
        End If
        If Not IO.File.Exists("D:\ActivityTest\Test2.txt") Then
            My.Computer.FileSystem.WriteAllText("D:\ActivityTest\Test2.txt", "This is test strings2", False)
        End If
    End Sub

    <TearDown()>
    Public Sub TearDown()
        Try
            For Each childFile In IO.Directory.GetFiles("D:\ActivityTest\TestDestination")
                My.Computer.FileSystem.DeleteFile(childFile)
            Next
            For Each childFile In IO.Directory.GetFiles("D:\ActivityTest")
                My.Computer.FileSystem.DeleteFile(childFile)
            Next
            My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest\TestDestination", FileIO.DeleteDirectoryOption.DeleteAllContents)
            My.Computer.FileSystem.DeleteDirectory("D:\ActivityTest", FileIO.DeleteDirectoryOption.DeleteAllContents)
        Catch ex As Exception

        End Try
    End Sub

    <TestCase("", "D:\ActivityTest\")>
    <TestCase("*", "D:\ActivityTest\")>
    <TestCase("TEST*", "D:\ActivityTest\")>
    Public Sub GetFolderListTestNormal(ByVal pattern As String, ByVal sourceFolder As String)

        Dim testActivity As New GetFolderListActivity With {
            .Pattern = pattern, .TargetFolder = sourceFolder}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        For Each getFile As String In wfInvoker.Output("Result")
            Console.WriteLine("Get Folder : " + getFile)
            Assert.True(IO.Directory.Exists(getFile))
        Next

    End Sub

    <TestCase("*.exe", "D:\ActivityTest\")>
    Public Sub GetFolderListTestIllegal(ByVal pattern As String, ByVal sourceFolder As String)

        Dim testActivity As New GetFolderListActivity With {
            .Pattern = pattern, .TargetFolder = sourceFolder}
        Dim wfInvoker As New WorkflowInvokerTest(testActivity)
        wfInvoker.TestActivity()

        For Each getFile As String In wfInvoker.Output("Result")
            Console.WriteLine("Get FFolderile : " + getFile)
            Assert.True(IO.Directory.Exists(getFile))
        Next

    End Sub

End Class
